package main

import (
	"flag"
	"fmt"
	"go_19/service/pulsar/pusar_topic_unsubscribe"
	"strings"
	"time"
)

func main() {
	fmt.Println("Pulsar Topic Subscribe delete")
	var param pusar_topic_unsubscribe.TopicUnsubscribeStruct
	pulsarBroker := flag.String("pulsar_broker", "", "required Pulsar Broker")
	pulsarTopic := flag.String("pulsar_topic", "", "required Topic")
	pulsarUnsubscribeNames := flag.String("pulsar_unsubscribe_names", "", "需要移除的订阅者名称 以,分割")
	flag.Parse()

	if *pulsarBroker == "" {
		panic("please input pulsar_broker!")
	}
	if *pulsarTopic == "" {
		panic("please input pulsar_topic!")
	}
	if *pulsarUnsubscribeNames == "" {
		panic("please input pulsar_unsubscribe_names!")
	}
	param.Topic.ClientOption.URL = *pulsarBroker
	param.Topic.Topic = *pulsarTopic
	param.Topic.ClientOption.ConnectionTimeout = time.Second * time.Duration(5)
	param.Topic.ClientOption.OperationTimeout = time.Second * time.Duration(30)
	param.Topic.ClientOption.MaxConnectionsPerBroker = 1
	param.Topic.SubscriptionType = 0

	subscribeNameArr := strings.Split(*pulsarUnsubscribeNames, ",")
	for _, subscribeName := range subscribeNameArr {
		param.UnSubscribeNames = append(param.UnSubscribeNames, subscribeName)
	}

	pusar_topic_unsubscribe.TopicUnsubscribe(param)
}
